#define  _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<assert.h>
#include<stdlib.h>
#include<stdbool.h>

typedef int BTDataType;
typedef struct BinaryTreeNode {
	BTDataType data;
	struct BinaryTreeNode* left;
	struct BinaryTreeNode* right;
}BTNode;

BTNode* BuyNode(BTDataType x) {
	BTNode* node = (BTNode*)malloc(sizeof(BTNode));
	if (node == NULL) {
		return NULL;
	}
	node->data = x;
	node->left = NULL;
	node->right = NULL;
	return node;
}

BTNode* CreatTree() 
{
	BTNode* node1 = BuyNode(1);
	BTNode* node2 = BuyNode(2);
	BTNode* node3 = BuyNode(3);
	BTNode* node4 = BuyNode(4);
	BTNode* node5 = BuyNode(5);
	BTNode* node6 = BuyNode(6);
	BTNode* node7 = BuyNode(7);

	node1->left = node2;
	node1->right = node4;
	node2->left = node3;
	node4->left = node5;
	node4->right = node6;
	node3->right = node7;

	return node1;
}

void PreOrder(BTNode* root) {
	if (root == NULL) {
		printf("NULL   ");
		return;
	}
	printf("%d   ", root->data);
	PreOrder(root->left);
	PreOrder(root->right);
}


void InOrder(BTNode* root) {
	if (root == NULL) {
		printf("NULL   ");
		return;
	}
	InOrder(root->left);
	printf("%d   ", root->data);
	InOrder(root->right);
}

void PostOrder(BTNode* root) {
	if (root == NULL) {
		printf("NULL   ");
		return;
	}
	PostOrder(root->left);
	PostOrder(root->right);
	printf("%d   ", root->data);
}

//int size = 0;
//void TreeSize(BTNode* root) {
//	if (root == NULL) {
//		return;
//	}
//	size++;
//	TreeSize(root->left);
//	TreeSize(root->right);
//}

int TreeSize(BTNode* root) {
	if (root == NULL) {
		return 0;
	}
	return TreeSize(root->left)+TreeSize(root->right)+1;
}

int TreeHeight(BTNode* root) {
	if (root == NULL) {
		return 0;
	}
	int max = TreeHeight(root->left);
	int min = TreeHeight(root->right);
	return max > min ? max+1 : min+1;
}

int TreeKLevel(BTNode* root,int k) {
	if (root == NULL) {
		return 0;
	}
	if (k == 1) {
		return 1;
	}
	int res=TreeKLevel(root->left, k - 1);
	res+=TreeKLevel(root->right, k - 1);
	return res;
}

BTNode* TreeFind(BTNode* root, int k) {
	if (root == NULL) {
		return root;
	}
	if (root->data == k) {
		return root;
	}
	BTNode* tem = NULL;
	tem = TreeFind(root->left,k) == NULL ? NULL : TreeFind(root->left,k);
	if (tem != NULL) {
		return tem;
	}
	tem = TreeFind(root->right,k) == NULL ? NULL : TreeFind(root->right,k);
	return tem;
}

//BTNode* queue[100];
//int head, tail;
//void LevelOrder(BTNode* root) {
//	if (root != NULL) {
//		queue[tail++] = root;
//	}
//	while (head != tail) {
//		BTNode* front = queue[head++];
//		printf("%d ", front->data);
//		if (front->left != NULL) {
//			queue[tail++] = front->left;
//		}
//		if (front->right != NULL) {
//			queue[tail++] = front->right;
//		}
//	}
//}

BTNode* queue[100];
int head, tail;

bool TreeComplete(BTNode* root) {
	if (root != NULL) {
		queue[tail++] = root;
	}
	while (head != tail) {
		BTNode* front = queue[head++];
		if (front == NULL) {
			break;
		}
		queue[tail++] = front->left;
		queue[tail++] = front->right;
	}

	while (head != tail) {
		BTNode* front = queue[head++];
		if (front != NULL) {
			return false;
		}
	}
	return true;
}

int main() {
	BTNode* root = CreatTree();
	bool res=TreeComplete(root);
	printf("%d ",res);
	return 0;
}